﻿Imports System.ServiceModel

Public Class frmRecuperaAcuseCancelacion
    Private _random As New Random

    Private Sub btnRecuperarAcuse_Click(sender As System.Object, e As System.EventArgs) Handles btnRecuperarAcuse.Click
        Dim transactionId As Long = _random.[Next]()
        Dim token As String = String.Empty
        Dim estatus As String = String.Empty
        Dim Errores As String = String.Empty
        Using Cancelacion = New SrvCancelation.CancelacionesClient()
            Dim Util = New Utilerias()
            Errores = Util.CreateToken(txtRFCEmisor.Text, transactionId, token)
            If (String.IsNullOrEmpty(Errores) = False) Then
                ShowUnknownError(Errores)
            End If
            Try
                Dim respuesta = Cancelacion.RecuperarAcuses(txtRFCEmisor.Text, token, transactionId, Guid.Parse(txtUUIDEntrada.Text), estatus)
                txtAcuseCancelacion.Text = respuesta
                txtEstatus.Text = estatus
                txtUUIDSalida.Text = txtUUIDEntrada.Text
            Catch validatioFault As FaultException(Of SrvCancelation.FallaValidacion)
                Using errorForm = New frmError(TranslateFault.ToValidationError(validatioFault.Detail))
                    errorForm.ShowDialog()
                End Using
            Catch serviceFault As FaultException(Of SrvCancelation.FallaServicio)
                Using errorForm = New frmError(TranslateFault.ToServiceError(serviceFault.Detail))
                    errorForm.ShowDialog()
                End Using
            Catch sessionFauld As FaultException(Of SrvCancelation.FallaSesion)
                Using errorForm = New frmError(TranslateFault.ToSessionError(sessionFauld.Detail))
                    errorForm.ShowDialog()
                End Using
            Catch ex As Exception
                ShowUnknownError(ex.Message)
            End Try
        End Using
    End Sub

    Public Sub ShowResult(ByVal message As String)
        MessageBox.Show([String].Format("{0}", message), "Ecodex UniTest")
    End Sub
    Public Sub ShowUnknownError(ByVal message As String)
        MessageBox.Show([String].Format("Error: {0}", message), "Ecodex UniTest")
    End Sub
    Public Sub ShowSessionError(ByVal [error] As Entity.SessionError)
        MessageBox.Show([String].Format("Status {0}: {1}", [error].Status.ToString(), [error].Description), "Ecodex UniTest")
    End Sub


  
End Class